package my.jwds.p198;

public class Rob {

    public static void main(String[] args) {
        Rob obj = new Rob();
        int [] nums = {226,174,214,16};
        System.out.println(obj.rob(nums));
    }

    public int rob(int[] nums) {
        if (nums.length == 1){return nums[0];};
        int [] dfs = new int[nums.length];
        dfs[0] = nums[0];
        dfs[1] = Math.max(nums[0],nums[1]);
        for (int i = 2; i < nums.length; i++) {
            dfs[i] =  Math.max(dfs[i-2]+nums[i],dfs[i-1]);
        }
        return dfs[dfs.length-1];
    }




}